#  This script is for use in spinning up the Dustbowl model
#  It inherits from the CONUS spinup script (Maxwell and Condon, Science)
# with restart info added from M Yazdi script for East River

set tcl_precision 17

set runname Baseline1

#
# Import the ParFlow TCL package
#
lappend auto_path $env(PARFLOW_DIR)/bin 
package require parflow
namespace import Parflow::*

pfset FileVersion 4

pfset Process.Topology.P       16
pfset Process.Topology.Q       16
pfset Process.Topology.R       1

set  nproc [expr [pfget Process.Topology.P]*[pfget Process.Topology.Q]*[pfget Process.Topology.R]]

#-----------------------------------------------------------------------------
### Initialize variables for restart
###-----------------------------------------------------------------------------
set log_file [open "restart.log" a 0600]
set rst_file clm_restart.tcl

if { [file exists $rst_file] == 1} { 
	source clm_restart.tcl
	set pfstep [expr int($istep)]
	puts "Restarting pfstep = $pfstep"
	
	#set the parflow counter to the clm counter -1
	set clmstep [expr int($pfstep+1)]
	puts "Restarting clmstep = $clmstep"

	#Record the restart
	set systemTime [clock seconds]
	
	puts $log_file "Restarting clmstep = $clmstep"
	puts $log_file  "The time is: [clock format $systemTime -format %H:%M:%S]"
	puts $log_file "The date is: [clock format $systemTime -format %D]"	
	close $log_file

	#Set the intial pressure file
	set ip [format $runname.out.press.%05d.pfb $pfstep]
       
	#Copy the clm driver with restart flags
	file copy -force ./drv_clmin.restart.dat ./drv_clmin.dat

	#Copy the restart files to the correct time stamp
	for {set i 0 } { $i < $nproc } { incr i 1 } {
		set fname_rst [format "clm.rst.%05d.$i" $pfstep]        
		exec cp clm.rst.00000.$i $fname_rst
                #set fname_rst [format "clm.rst.%05d.$i" $pfstep]
                #exec cp $fname_rst clm.rst.00000.$i
	}

	#Copy the kinsol log and the clm log so you have a copy saved
	#set fname_kin2 [format $runname.out.%05d.kinsol.log $pfstep]
       # exec cp $runname.out.kinsol.log $fname_kin2
       
       # set fname_clm2 [format CLM.out.clm.%05d.log $clmstep]
	#exec cp CLM.out.clm.log $fname_clm2


#If there isn't a restart file then start from scratch
#Note, the correct initial pressure and CLM restart files must be copied over manually from the previous year
} else {
	puts "** CLM restart tcl not found. Starting a new run from the begining..."
	puts $log_file "Starting New Run"    
	puts $log_file "$runname"

	#Copy inputs into the run directory
	file copy -force "~/pf_inputs/slopex_small_fixed.pfb" .
        file copy -force "~/pf_inputs/slopey_small_fixed.pfb" .
        file copy -force "~/pf_inputs/final_subsurf.pfb" .
        file copy -force "~/clm_inputs/drv_vegm.fixed_small.dat" .
        file copy -force "~/clm_inputs/drv_vegp.dat" .
	file copy -force "~/clm_inputs/drv_clmin.startup.dat" .
	file copy -force "~/clm_inputs/drv_clmin.restart.dat" .

	#Set the ParFlow counter to 0 and clm to 1
	set pfstep 0
	set clmstep [expr int($pfstep+1)]

	#set the initial conditions
	set ip "press.init.pfb"

	#Copy the clm driver file with the restart flags turned off
	file copy -force "./drv_clmin.startup.dat" ./drv_clmin.dat

}



#---------------------------------------------------------
# Computational Grid 
#---------------------------------------------------------
pfset ComputationalGrid.Lower.X           0.0
pfset ComputationalGrid.Lower.Y           0.0
pfset ComputationalGrid.Lower.Z           0.0

pfset ComputationalGrid.NX                1200
pfset ComputationalGrid.NY                1124
pfset ComputationalGrid.NZ               5

pfset ComputationalGrid.DX	         	1000.0
pfset ComputationalGrid.DY               1000.0
#"native" grid resolution is 2m everywhere X NZ=25 for 50m 
#computational domain.
pfset ComputationalGrid.DZ              100.0

#---------------------------------------------------------
# The Names of the GeomInputs 
#---------------------------------------------------------
pfset GeomInput.Names                 "domaininput soilinput indi_input"

pfset GeomInput.domaininput.GeomName  domain
pfset GeomInput.domaininput.InputType  Box

pfset GeomInput.soilinput.GeomName soil
pfset GeomInput.soilinput.InputType  Box

#---------------------------------------------------------
# Domain Geometry  
#---------------------------------------------------------
pfset Geom.domain.Lower.X                        0.0
pfset Geom.domain.Lower.Y                        0.0
pfset Geom.domain.Lower.Z                        0.0
 
pfset Geom.domain.Upper.X                        1200000.0
pfset Geom.domain.Upper.Y                        1124000.0
# this upper is synched to computational grid, not linked w/ Z multipliers
pfset Geom.domain.Upper.Z                        500.0
pfset Geom.domain.Patches             "x-lower x-upper y-lower y-upper z-lower z-upper"

#---------------------------------------------------------
# Soil Geometry 
#---------------------------------------------------------
pfset Geom.soil.Lower.X                        0.0
pfset Geom.soil.Lower.Y                        0.0
pfset Geom.soil.Lower.Z                        100.0
 
pfset Geom.soil.Upper.X                        1200000.0
pfset Geom.soil.Upper.Y                        1124000.0
# this upper is synched to computational grid, not linked w/ Z multipliers
pfset Geom.soil.Upper.Z                        500.0

#-----------------------------------------------------------------------------
# Subsurface Indicator Geometry Input 
#-----------------------------------------------------------------------------
pfset GeomInput.indi_input.InputType    IndicatorField
pfset GeomInput.indi_input.GeomNames    "s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 g1 g2 g3 g4 g5 g6 g7 g8"
pfset Geom.indi_input.FileName          "final_subsurf.pfb"
pfdist final_subsurf.pfb

pfset GeomInput.s1.Value    1
pfset GeomInput.s2.Value    2
pfset GeomInput.s3.Value    3
pfset GeomInput.s4.Value    4
pfset GeomInput.s5.Value    5
pfset GeomInput.s6.Value    6
pfset GeomInput.s7.Value    7
pfset GeomInput.s8.Value    8
pfset GeomInput.s9.Value    9
pfset GeomInput.s10.Value   10
pfset GeomInput.s11.Value   11
pfset GeomInput.s12.Value   12
pfset GeomInput.s13.Value   13

pfset GeomInput.g1.Value    21
pfset GeomInput.g2.Value    22
pfset GeomInput.g3.Value    23
pfset GeomInput.g4.Value    24
pfset GeomInput.g5.Value    25
pfset GeomInput.g6.Value    26
pfset GeomInput.g7.Value    27
pfset GeomInput.g8.Value    28

#--------------------------------------------
# variable dz assignments 
#------------------------------------------
pfset Solver.Nonlinear.VariableDz  True 
pfset dzScale.GeomNames            domain
pfset dzScale.Type            nzList
pfset dzScale.nzListNumber       5

# 5 layers, starts at 0 for the bottom to 5 at the top
# note this is opposite Noah/WRF
# layers are 0.1 m, 0.3 m, 0.6 m, 1.0 m, 100 m
pfset Cell.0.dzScale.Value 1.0
# 100 m * .01 = 1m 
pfset Cell.1.dzScale.Value 0.01
# 100 m * .006 = 0.6 m 
pfset Cell.2.dzScale.Value .006
# 100 m * 0.003 = 0.3 m 
pfset Cell.3.dzScale.Value .003
# 100 m * 0.001 = 0.1m = 10 cm which is default top Noah layer
pfset Cell.4.dzScale.Value 0.001

#-----------------------------------------------------------------------------
# Perm
#-----------------------------------------------------------------------------

pfset Geom.Perm.Names                 "domain s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 g1 g2 g3 g4 g5 g6 g7 g8"

# Values in m/hour

pfset Geom.domain.Perm.Type             Constant
pfset Geom.domain.Perm.Value            0.02

pfset Geom.s1.Perm.Type                 Constant
pfset Geom.s1.Perm.Value                0.269022595

pfset Geom.s2.Perm.Type                 Constant
pfset Geom.s2.Perm.Value                0.043630356

pfset Geom.s3.Perm.Type                 Constant
pfset Geom.s3.Perm.Value                0.015841225

pfset Geom.s4.Perm.Type                 Constant
pfset Geom.s4.Perm.Value                0.007582087

pfset Geom.s5.Perm.Type                 Constant
pfset Geom.s5.Perm.Value                0.01818816

pfset Geom.s6.Perm.Type                 Constant
pfset Geom.s6.Perm.Value                0.005009435

pfset Geom.s7.Perm.Type                 Constant
pfset Geom.s7.Perm.Value                 0.005492736

pfset Geom.s8.Perm.Type            Constant
pfset Geom.s8.Perm.Value           0.004675077

pfset Geom.s9.Perm.Type            Constant
pfset Geom.s9.Perm.Value           0.003386794

pfset Geom.s10.Perm.Type            Constant
pfset Geom.s10.Perm.Value           0.004783973

pfset Geom.s11.Perm.Type            Constant
pfset Geom.s11.Perm.Value           0.003979136

pfset Geom.s12.Perm.Type            Constant
pfset Geom.s12.Perm.Value           0.006162952

pfset Geom.s13.Perm.Type            Constant
pfset Geom.s13.Perm.Value           0.005009435


pfset Geom.g1.Perm.Type            Constant
pfset Geom.g1.Perm.Value           0.02

pfset Geom.g2.Perm.Type            Constant
pfset Geom.g2.Perm.Value           0.03

pfset Geom.g3.Perm.Type            Constant
pfset Geom.g3.Perm.Value           0.04

pfset Geom.g4.Perm.Type            Constant
pfset Geom.g4.Perm.Value           0.05

pfset Geom.g5.Perm.Type            Constant
pfset Geom.g5.Perm.Value           0.06

pfset Geom.g6.Perm.Type            Constant
pfset Geom.g6.Perm.Value           0.08

pfset Geom.g7.Perm.Type            Constant
pfset Geom.g7.Perm.Value           0.1

pfset Geom.g8.Perm.Type            Constant
pfset Geom.g8.Perm.Value           0.2


pfset Perm.TensorType               TensorByGeom

pfset Geom.Perm.TensorByGeom.Names  "domain soil"

pfset Geom.domain.Perm.TensorValX  1.0d0
pfset Geom.domain.Perm.TensorValY  1.0d0
pfset Geom.domain.Perm.TensorValZ  1.0d0

pfset Geom.soil.Perm.TensorValX  1.0d0
pfset Geom.soil.Perm.TensorValY  1.0d0
pfset Geom.soil.Perm.TensorValZ  1.0d0

#-----------------------------------------------------------------------------
# Specific Storage 
#-----------------------------------------------------------------------------

pfset SpecificStorage.Type            Constant
pfset SpecificStorage.GeomNames       "domain"
pfset Geom.domain.SpecificStorage.Value 1.0e-5


#-----------------------------------------------------------------------------
# Phases
#-----------------------------------------------------------------------------

pfset Phase.Names "water"

pfset Phase.water.Density.Type	        Constant
pfset Phase.water.Density.Value	        1.0

pfset Phase.water.Viscosity.Type	Constant
pfset Phase.water.Viscosity.Value	1.0

#-----------------------------------------------------------------------------
# Contaminants 
#-----------------------------------------------------------------------------

pfset Contaminants.Names			""

#-----------------------------------------------------------------------------
# Retardation
#-----------------------------------------------------------------------------

pfset Geom.Retardation.GeomNames           ""

#-----------------------------------------------------------------------------
# Gravity 
#-----------------------------------------------------------------------------

pfset Gravity				1.0

#-----------------------------------------------------------------------------
# Setup timing info 
#-----------------------------------------------------------------------------

# 
pfset TimingInfo.BaseUnit        1.0

pfset TimingInfo.StartCount    $pfstep
pfset TimingInfo.StartTime     $pfstep
pfset TimingInfo.DumpInterval    1 
pfset TimingInfo.StopTime       8760

pfset Solver.CLM.IstepStart     $clmstep
pfset Solver.CLM.CLMDumpInterval    1

pfset TimeStep.Type              Constant
pfset TimeStep.Value             1.0
#pfset TimeStep.Type				Growth
#pfset TimeStep.InitialStep		0.0001
#pfset TimeStep.GrowthFactor		1.4
#pfset TimeStep.MaxStep 			1.0
#pfset TimeStep.MinStep			0.0001

#-----------------------------------------------------------------------------
# Porosity 
#-----------------------------------------------------------------------------

#pfset Geom.Porosity.GeomNames          "domain"

#pfset Geom.domain.Porosity.Type          Constant
#pfset Geom.domain.Porosity.Value         0.25

pfset Geom.Porosity.GeomNames           "domain s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 g1 g2 g3 g4 g5 g6 g7 g8"
#pfset Geom.Porosity.GeomNames           "domain"

pfset Geom.domain.Porosity.Type         Constant
pfset Geom.domain.Porosity.Value        0.33

pfset Geom.s1.Porosity.Type    Constant
pfset Geom.s1.Porosity.Value   0.375

pfset Geom.s2.Porosity.Type    Constant
pfset Geom.s2.Porosity.Value   0.39

pfset Geom.s3.Porosity.Type    Constant
pfset Geom.s3.Porosity.Value   0.387

pfset Geom.s4.Porosity.Type    Constant
pfset Geom.s4.Porosity.Value   0.439

pfset Geom.s5.Porosity.Type    Constant
pfset Geom.s5.Porosity.Value   0.489

pfset Geom.s6.Porosity.Type    Constant
pfset Geom.s6.Porosity.Value   0.399

pfset Geom.s7.Porosity.Type    Constant
pfset Geom.s7.Porosity.Value   0.384

pfset Geom.s8.Porosity.Type            Constant
pfset Geom.s8.Porosity.Value           0.482

pfset Geom.s9.Porosity.Type            Constant
pfset Geom.s9.Porosity.Value           0.442

pfset Geom.s10.Porosity.Type            Constant
pfset Geom.s10.Porosity.Value           0.385

pfset Geom.s11.Porosity.Type            Constant
pfset Geom.s11.Porosity.Value           0.481

pfset Geom.s12.Porosity.Type            Constant
pfset Geom.s12.Porosity.Value           0.459

pfset Geom.s13.Porosity.Type            Constant
pfset Geom.s13.Porosity.Value           0.399

pfset Geom.g1.Porosity.Type            Constant
pfset Geom.g1.Porosity.Value           0.33

pfset Geom.g2.Porosity.Type            Constant
pfset Geom.g2.Porosity.Value           0.33

pfset Geom.g3.Porosity.Type            Constant
pfset Geom.g3.Porosity.Value           0.33

pfset Geom.g4.Porosity.Type            Constant
pfset Geom.g4.Porosity.Value           0.33

pfset Geom.g5.Porosity.Type            Constant
pfset Geom.g5.Porosity.Value           0.33

pfset Geom.g6.Porosity.Type            Constant
pfset Geom.g6.Porosity.Value           0.33

pfset Geom.g7.Porosity.Type            Constant
pfset Geom.g7.Porosity.Value           0.33

pfset Geom.g8.Porosity.Type            Constant
pfset Geom.g8.Porosity.Value           0.33


#-----------------------------------------------------------------------------
# Domain
#-----------------------------------------------------------------------------

pfset Domain.GeomName domain

#-----------------------------------------------------------------------------
# Relative Permeability 
#-----------------------------------------------------------------------------

#pfset Phase.RelPerm.Type               VanGenuchten
#pfset Phase.RelPerm.GeomNames          "domain soil"

#pfset Geom.domain.RelPerm.Alpha         0.3
#pfset Geom.domain.RelPerm.N             3. 

#pfset Geom.soil.RelPerm.Alpha         1.
#pfset Geom.soil.RelPerm.N             2. 

pfset Phase.RelPerm.Type               VanGenuchten
pfset Phase.RelPerm.GeomNames      "domain s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13"
#pfset Phase.RelPerm.GeomNames      "domain s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13"
#pfset Phase.RelPerm.GeomNames      "domain"

pfset Geom.domain.RelPerm.Alpha    1.
pfset Geom.domain.RelPerm.N        3.
pfset Geom.domain.RelPerm.NumSamplePoints   20000
pfset Geom.domain.RelPerm.MinPressureHead   -300
pfset Geom.domain.RelPerm.InterpolationMethod  Linear


pfset Geom.s1.RelPerm.Alpha        3.548
#pfset Geom.s1.RelPerm.Alpha        2.5
pfset Geom.s1.RelPerm.N            4.162
pfset Geom.s1.RelPerm.NumSamplePoints   20000
pfset Geom.s1.RelPerm.MinPressureHead   -300
pfset Geom.s1.RelPerm.InterpolationMethod  Linear

pfset Geom.s2.RelPerm.Alpha        3.467
pfset Geom.s2.RelPerm.N            2.738
pfset Geom.s2.RelPerm.NumSamplePoints   20000
pfset Geom.s2.RelPerm.MinPressureHead   -300
pfset Geom.s2.RelPerm.InterpolationMethod  Linear

pfset Geom.s3.RelPerm.Alpha        2.692
pfset Geom.s3.RelPerm.N            2.445
pfset Geom.s3.RelPerm.NumSamplePoints   20000
pfset Geom.s3.RelPerm.MinPressureHead   -300
pfset Geom.s3.RelPerm.InterpolationMethod  Linear

pfset Geom.s4.RelPerm.Alpha        0.501
pfset Geom.s4.RelPerm.N            2.659
pfset Geom.s4.RelPerm.NumSamplePoints   20000
pfset Geom.s4.RelPerm.MinPressureHead   -300
pfset Geom.s4.RelPerm.InterpolationMethod  Linear

pfset Geom.s5.RelPerm.Alpha        0.661
pfset Geom.s5.RelPerm.N            2.659
pfset Geom.s5.RelPerm.NumSamplePoints   20000
pfset Geom.s5.RelPerm.MinPressureHead   -300
pfset Geom.s5.RelPerm.InterpolationMethod  Linear

pfset Geom.s6.RelPerm.Alpha        1.122
pfset Geom.s6.RelPerm.N            2.479
pfset Geom.s6.RelPerm.NumSamplePoints   20000
pfset Geom.s6.RelPerm.MinPressureHead   -300
pfset Geom.s6.RelPerm.InterpolationMethod  Linear

pfset Geom.s7.RelPerm.Alpha        2.089
pfset Geom.s7.RelPerm.N            2.318
pfset Geom.s7.RelPerm.NumSamplePoints   20000
pfset Geom.s7.RelPerm.MinPressureHead   -300
pfset Geom.s7.RelPerm.InterpolationMethod  Linear

pfset Geom.s8.RelPerm.Alpha        0.832
pfset Geom.s8.RelPerm.N            2.514
pfset Geom.s8.RelPerm.NumSamplePoints   20000
pfset Geom.s8.RelPerm.MinPressureHead   -300
pfset Geom.s8.RelPerm.InterpolationMethod  Linear

pfset Geom.s9.RelPerm.Alpha        1.585
pfset Geom.s9.RelPerm.N            2.413
pfset Geom.s9.RelPerm.NumSamplePoints   20000
pfset Geom.s9.RelPerm.MinPressureHead   -300
pfset Geom.s9.RelPerm.InterpolationMethod  Linear

pfset Geom.s10.RelPerm.Alpha        3.311
#pfset Geom.s10.RelPerm.Alpha        2.
pfset Geom.s10.RelPerm.N            2.202
pfset Geom.s10.RelPerm.NumSamplePoints   20000
pfset Geom.s10.RelPerm.MinPressureHead   -300
pfset Geom.s10.RelPerm.InterpolationMethod  Linear

pfset Geom.s11.RelPerm.Alpha        1.622
pfset Geom.s11.RelPerm.N            2.318
pfset Geom.s11.RelPerm.NumSamplePoints   20000
pfset Geom.s11.RelPerm.MinPressureHead   -300
pfset Geom.s11.RelPerm.InterpolationMethod  Linear

pfset Geom.s12.RelPerm.Alpha        1.514
pfset Geom.s12.RelPerm.N            2.259
pfset Geom.s12.RelPerm.NumSamplePoints   20000
pfset Geom.s12.RelPerm.MinPressureHead   -300
pfset Geom.s12.RelPerm.InterpolationMethod  Linear

pfset Geom.s13.RelPerm.Alpha        1.122
pfset Geom.s13.RelPerm.N            2.479
pfset Geom.s13.RelPerm.NumSamplePoints   20000
pfset Geom.s13.RelPerm.MinPressureHead   -300
pfset Geom.s13.RelPerm.InterpolationMethod  Linear


#---------------------------------------------------------
# Saturation 
#---------------------------------------------------------

#pfset Phase.Saturation.Type              VanGenuchten
#pfset Phase.Saturation.GeomNames         "domain soil"

#pfset Geom.domain.Saturation.Alpha        0.3
#pfset Geom.domain.Saturation.N            3.
#pfset Geom.domain.Saturation.SRes         0.1
#pfset Geom.domain.Saturation.SSat         1.0

#pfset Geom.soil.Saturation.Alpha        1.0
#pfset Geom.soil.Saturation.N            2.
#pfset Geom.soil.Saturation.SRes         0.1
#pfset Geom.soil.Saturation.SSat         1.0

pfset Phase.Saturation.Type              VanGenuchten
pfset Phase.Saturation.GeomNames         "domain s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13"
#pfset Phase.Saturation.GeomNames         "domain s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13"
#pfset Phase.Saturation.GeomNames         "domain"
#
# @RMM added very low Sres to help with dry / large evap
#
pfset Geom.domain.Saturation.Alpha        1.
pfset Geom.domain.Saturation.N            3.
#pfset Geom.domain.Saturation.SRes         0.1
pfset Geom.domain.Saturation.SRes         0.001
pfset Geom.domain.Saturation.SSat         1.0

pfset Geom.s1.Saturation.Alpha        3.548
pfset Geom.s1.Saturation.N            4.162
pfset Geom.s1.Saturation.SRes         0.0001
#pfset Geom.s1.Saturation.SRes         0.1
pfset Geom.s1.Saturation.SSat         1.0

pfset Geom.s2.Saturation.Alpha        3.467
#pfset Geom.s2.Saturation.Alpha        2.5
pfset Geom.s2.Saturation.N            2.738
pfset Geom.s2.Saturation.SRes         0.0001
#pfset Geom.s2.Saturation.SRes         0.1
pfset Geom.s2.Saturation.SSat         1.0

pfset Geom.s3.Saturation.Alpha        2.692
pfset Geom.s3.Saturation.N            2.445
pfset Geom.s3.Saturation.SRes         0.0001
#pfset Geom.s3.Saturation.SRes         0.1
pfset Geom.s3.Saturation.SSat         1.0

pfset Geom.s4.Saturation.Alpha        0.501
pfset Geom.s4.Saturation.N            2.659
#pfset Geom.s4.Saturation.SRes         0.0001
pfset Geom.s4.Saturation.SRes         0.1
pfset Geom.s4.Saturation.SSat         1.0

pfset Geom.s5.Saturation.Alpha        0.661
pfset Geom.s5.Saturation.N            2.659
pfset Geom.s5.Saturation.SRes         0.0001
#pfset Geom.s5.Saturation.SRes         0.1
pfset Geom.s5.Saturation.SSat         1.0

pfset Geom.s6.Saturation.Alpha        1.122
pfset Geom.s6.Saturation.N            2.479
pfset Geom.s6.Saturation.SRes         0.0001
#pfset Geom.s6.Saturation.SRes         0.1
pfset Geom.s6.Saturation.SSat         1.0

pfset Geom.s7.Saturation.Alpha        2.089
pfset Geom.s7.Saturation.N            2.318
pfset Geom.s7.Saturation.SRes         0.0001
#pfset Geom.s7.Saturation.SRes         0.1
pfset Geom.s7.Saturation.SSat         1.0

pfset Geom.s8.Saturation.Alpha        0.832
pfset Geom.s8.Saturation.N            2.514
pfset Geom.s8.Saturation.SRes         0.0001
#pfset Geom.s8.Saturation.SRes         0.1
pfset Geom.s8.Saturation.SSat         1.0

pfset Geom.s9.Saturation.Alpha        1.585
pfset Geom.s9.Saturation.N            2.413
pfset Geom.s9.Saturation.SRes         0.0001
#pfset Geom.s9.Saturation.SRes         0.1
pfset Geom.s9.Saturation.SSat         1.0

pfset Geom.s10.Saturation.Alpha        3.311
#pfset Geom.s10.Saturation.Alpha        2.
pfset Geom.s10.Saturation.N            2.202
pfset Geom.s10.Saturation.SRes         0.0001
#pfset Geom.s10.Saturation.SRes         0.1
pfset Geom.s10.Saturation.SSat         1.0

pfset Geom.s11.Saturation.Alpha        1.622
pfset Geom.s11.Saturation.N            2.318
pfset Geom.s11.Saturation.SRes         0.0001
#pfset Geom.s11.Saturation.SRes         0.1
pfset Geom.s11.Saturation.SSat         1.0

pfset Geom.s12.Saturation.Alpha        1.514
pfset Geom.s12.Saturation.N            2.259
pfset Geom.s12.Saturation.SRes         0.0001
#pfset Geom.s12.Saturation.SRes         0.1
pfset Geom.s12.Saturation.SSat         1.0

pfset Geom.s13.Saturation.Alpha        1.122
pfset Geom.s13.Saturation.N            2.479
pfset Geom.s13.Saturation.SRes         0.0001
#pfset Geom.s13.Saturation.SRes         0.1
pfset Geom.s13.Saturation.SSat         1.0



#-----------------------------------------------------------------------------
# Wells 
#-----------------------------------------------------------------------------
pfset Wells.Names                           ""

#-----------------------------------------------------------------------------
# Time Cycles
#-----------------------------------------------------------------------------

pfset Cycle.Names "constant"
pfset Cycle.constant.Names              "alltime"
pfset Cycle.constant.alltime.Length      10000000
pfset Cycle.constant.Repeat             -1

 
#-----------------------------------------------------------------------------
# Boundary Conditions: Pressure
#-----------------------------------------------------------------------------
pfset BCPressure.PatchNames                   [pfget Geom.domain.Patches]

pfset Patch.x-lower.BCPressure.Type		      FluxConst
pfset Patch.x-lower.BCPressure.Cycle		      "constant"
pfset Patch.x-lower.BCPressure.alltime.Value	      0.0

pfset Patch.y-lower.BCPressure.Type		      FluxConst
pfset Patch.y-lower.BCPressure.Cycle		      "constant"
pfset Patch.y-lower.BCPressure.alltime.Value	      0.0

pfset Patch.z-lower.BCPressure.Type		      FluxConst
pfset Patch.z-lower.BCPressure.Cycle		      "constant"
pfset Patch.z-lower.BCPressure.alltime.Value	       1.14155E-05  
pfset Patch.z-lower.BCPressure.alltime.Value	       0.0 

pfset Patch.x-upper.BCPressure.Type		      FluxConst
pfset Patch.x-upper.BCPressure.Cycle		      "constant"
pfset Patch.x-upper.BCPressure.alltime.Value	      0.0

pfset Patch.y-upper.BCPressure.Type		      FluxConst
pfset Patch.y-upper.BCPressure.Cycle		      "constant"
pfset Patch.y-upper.BCPressure.alltime.Value	      0.0

pfset Patch.z-upper.BCPressure.Type		      OverlandFlow
pfset Patch.z-upper.BCPressure.Cycle		      "constant"
pfset Patch.z-upper.BCPressure.alltime.Value	     0.0 

# PmE flux 
#pfset Solver.EvapTransFile    True
#pfset Solver.EvapTrans.FileName  "RiverForcing.pfb"
#pfdist "RiverForcing.pfb"


#---------------------------------------------------------
# Topo slopes in x-direction 
#---------------------------------------------------------

pfset TopoSlopesX.Type "PFBFile"
pfset TopoSlopesX.GeomNames "domain"
pfset TopoSlopesX.FileName slopex_small_fixed.pfb


#---------------------------------------------------------
# Topo slopes in y-direction 
#---------------------------------------------------------

pfset TopoSlopesY.Type "PFBFile"
pfset TopoSlopesY.GeomNames "domain"
pfset TopoSlopesY.FileName   slopey_small_fixed.pfb

#---------------------------------------------------------
#  Distribute slopes
#---------------------------------------------------------

pfset ComputationalGrid.NZ                1 


pfdist slopex_small_fixed.pfb
pfdist slopey_small_fixed.pfb

pfset ComputationalGrid.NZ                5 

#---------------------------------------------------------
# Mannings coefficient 
#---------------------------------------------------------

pfset Mannings.Type "Constant"
pfset Mannings.GeomNames "domain"
#pfset Mannings.Geom.domain.Value 1.0e-5
pfset Mannings.Geom.domain.Value 5.0e-5

#-----------------------------------------------------------------------------
# Phase sources:
#-----------------------------------------------------------------------------

pfset PhaseSources.water.Type                         Constant
pfset PhaseSources.water.GeomNames                    domain
pfset PhaseSources.water.Geom.domain.Value        0.0

#-----------------------------------------------------------------------------
# Exact solution specification for error calculations
#-----------------------------------------------------------------------------

pfset KnownSolution                                    NoKnownSolution


#-----------------------------------------------------------------------------
# Set solver parameters
#-----------------------------------------------------------------------------

pfset Solver                                             Richards
pfset Solver.MaxIter                                     25000

pfset Solver.TerrainFollowingGrid                        True


pfset Solver.Nonlinear.MaxIter                           2000 
pfset Solver.Nonlinear.ResidualTol                       1e-5
pfset Solver.Nonlinear.EtaValue                          0.0001


pfset Solver.PrintSubsurf				False
pfset  Solver.Drop                                      1E-20
pfset Solver.AbsTol                                     1E-10


#pfset Solver.Nonlinear.EtaChoice                         EtaConstant
#pfset Solver.Nonlinear.EtaValue                          0.01
pfset Solver.Nonlinear.UseJacobian                       True 
#pfset Solver.Nonlinear.UseJacobian                       False 
pfset Solver.Nonlinear.DerivativeEpsilon                 1e-16
pfset Solver.Nonlinear.StepTol				 1e-20
pfset Solver.Nonlinear.Globalization                     LineSearch
pfset Solver.Linear.KrylovDimension                      250
pfset Solver.Linear.MaxRestarts                           5
pfset Solver.MaxConvergenceFailures			 5

pfset Solver.Linear.Preconditioner                       MGSemi
pfset Solver.Linear.Preconditioner                       PFMG
#pfset Solver.Linear.Preconditioner                       SMG
pfset Solver.Linear.Preconditioner.PCMatrixType     FullJacobian
#pfset OverlandFlowDiffusive  1


# CLM:
pfset Solver.LSM                                      CLM
pfset Solver.CLM.CLMFileDir                           "clm_output/"
pfset Solver.CLM.Print1dOut                           False
pfset Solver.BinaryOutDir                             False
#pfset Solver.CLM.CLMDumpInterval                      5

pfset Solver.CLM.EvapBeta                             Linear
pfset Solver.CLM.VegWaterStress                       Saturation
pfset Solver.CLM.ResSat                               0.2
pfset Solver.CLM.WiltingPoint                         0.2
pfset Solver.CLM.FieldCapacity                        1.00
pfset Solver.CLM.IrrigationType                       none

pfset Solver.CLM.MetForcing                           3D
pfset Solver.CLM.MetFileName                          "NLDAS"
pfset Solver.CLM.MetFilePath                      /global/cscratch1/sd/ahein/Forcing/1985.forcings.subset
pfset Solver.CLM.MetFileNT                          12


pfset Solver.CLM.RootZoneNZ                         4
pfset Solver.CLM.SoiLayer                           4
pfset Solver.CLM.ReuseCount                         1
pfset Solver.CLM.WriteLogs                          False
pfset Solver.CLM.WriteLastRST                       True
pfset Solver.CLM.DailyRST                       True
pfset Solver.CLM.SingleFile                       True

pfset Solver.PrintSubsurfData                         True
#pfset Solver.PrintLSMSink                        True 
pfset Solver.PrintPressure                            True
pfset Solver.PrintSaturation                          True
pfset Solver.WriteCLMBinary                           False
pfset Solver.PrintMask                                True
pfset Solver.PrintCLM                                 True

#---------------------------------------------------------
# Initial conditions: water pressure 
#---------------------------------------------------------

pfset Geom.domain.ICPressure.RefGeom                    domain
pfset Geom.domain.ICPressure.RefPatch                   z-lower

# Initial conditions from full CONUS output 
pfset ICPressure.Type                                   PFBFile
pfset ICPressure.GeomNames                              domain
pfset Geom.domain.ICPressure.FileName       $ip
pfdist  $ip

#spinup key
# True=skim pressures, False = regular (default)
#pfset Solver.Spinup           True
pfset Solver.Spinup           False 

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------


pfwritedb $runname
